package com.polarrose.wsf.validator;

import java.math.BigDecimal;

public class RangeValidator implements Validator<Number> {

	private BigDecimal minValue;
	private BigDecimal maxValue;

	public void validate(Number o)
        throws ValidatorException
    {
		BigDecimal value = new BigDecimal(o.doubleValue());
        if (value.compareTo(minValue) < 0 || value.compareTo(maxValue) > 0) {
            throw new ValidatorException("Value is not in excepted range [" + minValue.toString() + "," + maxValue.toString() + "]");
        }
	}

	public void setMaxValue(String maxValue) {
		this.maxValue = new BigDecimal(maxValue);
	}

	public void setMinValue(String minValue) {
		this.minValue = new BigDecimal(minValue);
	}
}
